/*
 * Copyright (c) 2011. c.mueller
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * The Software shall be used for Good, not Evil.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package de.altitude.cimuelle.commandhandles.customcommands;

import de.altitude.cimuelle.MessageBundle;
import de.altitude.cimuelle.utils.StringUtils;
import de.altitudecustomcommands.Player;
import de.altitudecustomcommands.playerHandler;
import org.apache.log4j.Logger;

import static de.altitude.cimuelle.utils.ServerOperations.sendCommand;
import static de.altitude.cimuelle.utils.ServerOperations.sendServerMessage;

/**
 * Class description:
 * <p/>
 * User: cybernaut
 * Date: 08.10.11
 * Time: 16:16
 */
public class MovePlayersToLeft {
    private final static Logger LOGGER = Logger.getLogger("MovePlayersToLeft");

    private final playerHandler playerList;

    public MovePlayersToLeft(playerHandler playerList) {
        this.playerList = playerList;
    }

    public void moveAllPlayersToLeft(String port) {
        sendServerMessage(port, MessageBundle.getString("sgoWestInfo1Start"));
        for (Player player : playerList.getPlayersByPort(port)) {
            if (!player.playerIsBot()) {
                StringBuilder sb = new StringBuilder();
                sb.append(port);
                sb.append(",console,assignTeam \"");
                sb.append(StringUtils.addslashes(player.getName()));
                sb.append("\" 0");
                sendCommand(sb.toString());
            }
        }
        sendServerMessage(port, MessageBundle.getString("sgoWestInfo2End"));
    }
}
